﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="edit.aspx.cs" Inherits="Joyintech.Admin.inpiao365.general.system.role.edit" %>

<%@ Register Src="~/checkRight.ascx" TagName="checkRight" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>角色编辑</title>
    <script language="javascript" type="text/javascript">
        var DG = frameElement.lhgDG;
        function ok() {
            // 这里写你要操作的代码，最后写刷新代码 
            DG.curWin.location.href = DG.curWin.location.href;
        } 
    </script>

    
    <script language="javascript" type="text/javascript">
        function checkedAll() {
            //alert("abc");
            var oo = document.getElementsByTagName("input");
            var selectstate = document.getElementById("selectAll");
            for (var k = 0, len = oo.length; k < len; k++) {
                var e = oo[k];
                if (e.type == "checkbox") {
                    e.checked = selectstate.checked;
                }
            }
        }

        //获取元素指定tagName的父元素
        function public_GetParentByTagName(element, tagName) {
            var parent = element.parentNode;
            var upperTagName = tagName.toUpperCase();
            //如果这个元素还不是想要的tag就继续上溯
            while (parent && (parent.tagName.toUpperCase() != upperTagName)) {
                parent = parent.parentNode ? parent.parentNode : parent.parentElement;
            }
            return parent;
        }

        //设置节点的父节点Cheched——该节点可访问，则他的父节点也必能访问
        function setParentChecked(objNode) {
            var objParentDiv = public_GetParentByTagName(objNode, "div");
            if (objParentDiv == null || objParentDiv == "undefined") {
                return;
            }
            var objID = objParentDiv.getAttribute("ID");
            objID = objID.substring(0, objID.indexOf("Nodes"));
            objID = objID + "CheckBox";
            var objParentCheckBox = document.getElementById(objID);
            if (objParentCheckBox == null || objParentCheckBox == "undefined") {
                return;
            }
            if (objParentCheckBox.tagName != "INPUT" && objParentCheckBox.type == "checkbox")
                return;
            objParentCheckBox.checked = true;
            setParentChecked(objParentCheckBox);
        }

        //设置节点的子节点uncheched——该节点不可访问，则他的子节点也不能访问
        function setChildUnChecked(divID) {
            var objchild = divID.children;
            var count = objchild.length;
            for (var i = 0; i < objchild.length; i++) {
                var tempObj = objchild[i];
                if (tempObj.tagName == "INPUT" && tempObj.type == "checkbox") {
                    tempObj.checked = false;
                }
                setChildUnChecked(tempObj);
            }
        }

        //设置节点的子节点cheched——该节点可以访问，则他的子节点也都能访问
        function setChildChecked(divID) {
            var objchild = divID.children;
            var count = objchild.length;
            for (var i = 0; i < objchild.length; i++) {
                var tempObj = objchild[i];
                if (tempObj.tagName == "INPUT" && tempObj.type == "checkbox") {
                    tempObj.checked = true;
                }
                setChildChecked(tempObj);
            }
        }

        //触发事件
        function CheckEvent() {

            var objNode = event.srcElement;

            if (objNode.tagName != "INPUT" || objNode.type != "checkbox")
                return;

            if (objNode.checked == true) {
                setParentChecked(objNode);
                var objID = objNode.getAttribute("ID");
                var objID = objID.substring(0, objID.indexOf("CheckBox"));
                var objParentDiv = document.getElementById(objID + "Nodes");
                if (objParentDiv == null || objParentDiv == "undefined") {
                    return;
                }
                setChildChecked(objParentDiv);
            }
            else {
                var objID = objNode.getAttribute("ID");
                var objID = objID.substring(0, objID.indexOf("CheckBox"));
                var objParentDiv = document.getElementById(objID + "Nodes");
                if (objParentDiv == null || objParentDiv == "undefined") {
                    setParentUnChecked(objNode);
                    return;
                }
                setChildUnChecked(objParentDiv);
                setParentUnChecked(objNode);
            }
        }

        function setParentUnChecked(objNode) {
            var objParentDiv = public_GetParentByTagName(objNode, "div");
            if (objParentDiv == null || objParentDiv == "undefined") {
                return;
            }

            var objID = objParentDiv.getAttribute("ID");
            objID = objID.substring(0, objID.indexOf("Nodes"));
            objID = objID + "CheckBox";
            var objParentCheckBox = document.getElementById(objID);
            if (objParentCheckBox == null || objParentCheckBox == "undefined") {
                return;
            }
            if (objParentCheckBox.tagName != "INPUT" && objParentCheckBox.type == "checkbox")
                return;
            var isChecked = GetChildChecked(objParentDiv);
            objParentCheckBox.checked = isChecked;
            if (isChecked == false)
                setParentUnChecked(objParentCheckBox);
        }
        function GetChildChecked(div) {
            var isChecked = false;
            var checkBoxs = div.getElementsByTagName('INPUT');
            for (var i = 0; i < checkBoxs.length; i++) {
                if (checkBoxs[i].type == 'checkbox') {
                    if (checkBoxs[i].checked) {
                        isChecked = true;
                        break;
                    }
                }
            }
            return isChecked;
        }
          
    </script>
    <script language="javascript" type="text/javascript">
        //获取元素指定tagName的父元素
        function public_GetParentByTagName(element, tagName) {
            var parent = element.parentNode;
            var upperTagName = tagName.toUpperCase();
            //如果这个元素还不是想要的tag就继续上溯
            while (parent && (parent.tagName.toUpperCase() != upperTagName)) {
                parent = parent.parentNode ? parent.parentNode : parent.parentElement;
            }
            return parent;
        }

        //设置节点的父节点Cheched——该节点可访问，则他的父节点也必能访问
        function setParentChecked(objNode) {
            var objParentDiv = public_GetParentByTagName(objNode, "div");
            if (objParentDiv == null || objParentDiv == "undefined") {
                return;
            }
            var objID = objParentDiv.getAttribute("ID");
            objID = objID.substring(0, objID.indexOf("Nodes"));
            objID = objID + "CheckBox";
            var objParentCheckBox = document.getElementById(objID);
            if (objParentCheckBox == null || objParentCheckBox == "undefined") {
                return;
            }
            if (objParentCheckBox.tagName != "INPUT" && objParentCheckBox.type == "checkbox")
                return;
            objParentCheckBox.checked = true;
            setParentChecked(objParentCheckBox);
        }

        //设置节点的子节点uncheched——该节点不可访问，则他的子节点也不能访问
        function setChildUnChecked(divID) {
            var objchild = divID.children;
            var count = objchild.length;
            for (var i = 0; i < objchild.length; i++) {
                var tempObj = objchild[i];
                if (tempObj.tagName == "INPUT" && tempObj.type == "checkbox") {
                    tempObj.checked = false;
                }
                setChildUnChecked(tempObj);
            }
        }

        //设置节点的子节点cheched——该节点可以访问，则他的子节点也都能访问
        function setChildChecked(divID) {
            var objchild = divID.children;
            var count = objchild.length;
            for (var i = 0; i < objchild.length; i++) {
                var tempObj = objchild[i];
                if (tempObj.tagName == "INPUT" && tempObj.type == "checkbox") {
                    tempObj.checked = true;
                }
                setChildChecked(tempObj);
            }
        }

        //触发事件
        function CheckEvent() {

            var objNode = event.srcElement;

            if (objNode.tagName != "INPUT" || objNode.type != "checkbox")
                return;

            if (objNode.checked == true) {
                setParentChecked(objNode);
                var objID = objNode.getAttribute("ID");
                var objID = objID.substring(0, objID.indexOf("CheckBox"));
                var objParentDiv = document.getElementById(objID + "Nodes");
                if (objParentDiv == null || objParentDiv == "undefined") {
                    return;
                }
                setChildChecked(objParentDiv);
            }
            else {
                var objID = objNode.getAttribute("ID");
                var objID = objID.substring(0, objID.indexOf("CheckBox"));
                var objParentDiv = document.getElementById(objID + "Nodes");
                if (objParentDiv == null || objParentDiv == "undefined") {
                    setParentUnChecked(objNode);
                    return;
                }
                setChildUnChecked(objParentDiv);
                setParentUnChecked(objNode);
            }
        }

        function setParentUnChecked(objNode) {
            var objParentDiv = public_GetParentByTagName(objNode, "div");
            if (objParentDiv == null || objParentDiv == "undefined") {
                return;
            }

            var objID = objParentDiv.getAttribute("ID");
            objID = objID.substring(0, objID.indexOf("Nodes"));
            objID = objID + "CheckBox";
            var objParentCheckBox = document.getElementById(objID);
            if (objParentCheckBox == null || objParentCheckBox == "undefined") {
                return;
            }
            if (objParentCheckBox.tagName != "INPUT" && objParentCheckBox.type == "checkbox")
                return;
            var isChecked = GetChildChecked(objParentDiv);
            objParentCheckBox.checked = isChecked;
            if (isChecked == false)
                setParentUnChecked(objParentCheckBox);
        }
        function GetChildChecked(div) {
            var isChecked = false;
            var checkBoxs = div.getElementsByTagName('INPUT');
            for (var i = 0; i < checkBoxs.length; i++) {
                if (checkBoxs[i].type == 'checkbox') {
                    if (checkBoxs[i].checked) {
                        isChecked = true;
                        break;
                    }
                }
            }
            return isChecked;
        }
          
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="position">
        <span>角色编辑</span>
    </div>
    <br />
    <jui:HFPanel ID="HFPanel1" runat="server">
        <table border="0" cellpadding="0" cellspacing="1" width="450" align="center" class="datatable">
            <tr class="row1">
                <td class="check">
                    角色名称：
                </td>
                <td>
                    <jui:HFTextBox ID="RoleName" runat="server" ChineseName="角色名称" PropertyName="RoleName"></jui:HFTextBox>
                </td>
            </tr>
            <tr class="row2">
                <td class="check">
                    角色备注：
                </td>
                <td>
                    <jui:HFTextBox ID="RoleRemark" runat="server" ChineseName="角色备注" PropertyName="RoleRemark"></jui:HFTextBox>
                    <input type="checkbox" value="全选" id="selectAll" onclick="checkedAll()" />全选
                </td>
            </tr>
            <tr class="row1">
                <td class="check">
                    菜单权限：
                </td>
                <td class="fontL">
                    <asp:TreeView ID="treeViewMenu" runat="server" ShowCheckBoxes="All" onclick="CheckEvent()">
                    </asp:TreeView>
                </td>
            </tr>
            <tr class="row2">
                <td colspan="2" class="fontC" align="center">
                    <jui:HFButton ID="btnSave" runat="server" CssClass="BigButton" Text="确定" OnClick="btnSave_Click" />
                    &nbsp;&nbsp;
                    <input type="button" value="返回" class="BigButton" onclick="DG.cancel();" />
                </td>
            </tr>
        </table>
    </jui:HFPanel>
    <uc1:checkRight ID="checkRight1" runat="server" />
    </form>
</body>
</html>
